<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var backspace = function (s, t) {
      const build = (str) => {
        let res = [];
        for (let a of str) {
          // 如果为退格键就出栈，否则就出栈
          res[a == "#" ? "pop" : "push"](a);
        }
        return res.join("");
      };
      // 比较经过处理后的俩字符串 s 及 t 是否相同

      return build(s) == build(t);
    };
    console.log(backspace(s = "ab#c", t = "ad#c"))
  </script>
</body>

</html>